package com.nineclock.system.controller;

import com.nineclock.api.sysrem.SysCompanyControllerApi;
import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.*;

import com.nineclock.system.service.SysCompanyService;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("company")
public class SysCompanyController implements SysCompanyControllerApi {

    @Autowired
    private SysCompanyService companyService;

    /**
     * 获取企业的详细信息
     * @return
     */
    @Override
    @GetMapping
    public Result<SysCompanyDTO> queryCompanyInfo() {
        SysCompanyDTO sysCompanyDTO = companyService.queryCompanyInfo();
        return Result.success(sysCompanyDTO);
    }

    /**
     * 上传企业logo
     * @param file
     * @return
     */
    @Override
    @PostMapping("/uploadOSS")
    public Result<String> uploadCompanyLogo(MultipartFile file) {
       String logoUrl= companyService.uploadCompanyLogo(file);
        return Result.success(logoUrl);
    }

    /**
     * 更新企业基本信息
     * @param sysCompanyDTO
     * @return
     */
    @Override
    @PutMapping
    public Result updateCompanyInfo(@RequestBody  SysCompanyDTO sysCompanyDTO) {
        companyService.updateCompanyInfo(sysCompanyDTO);
        return Result.success();
    }

    @Autowired
    private SysCompanyUserService companyUserService;


    @Override
    @GetMapping("/getCurrentAdmin")
    public Result<SysCompanyUserDTO> getCurrentAdmin() {
        SysCompanyUserDTO companyUserDTO= companyUserService.getCurrentAdmin();
        return Result.success(companyUserDTO);
    }

    @Override
    @PostMapping("/config/admin")
    public Result changeSysAdmin(@RequestBody SysChangeMainManagerDTO sysChangeMainManagerDTO) {

        companyService.changeSysAdmin(sysChangeMainManagerDTO);
        return Result.success();
    }
    /**
     * 根据企业的关键字名称, 模糊查询企业列表
     * @param keyword
     * @return
     */
    @Override
    @GetMapping("/list")
    public Result<List<SysCompanyDTO>> queryCompanyByName(String keyword) {
        List<SysCompanyDTO> companyDTOList= companyService.queryCompanyByName(keyword);
        return Result.success(companyDTOList);
    }

    /**
     * 申请加入企业
     * @param sysApplyJoinCompanyUserDTO
     * @return
     */
    @Override
    @PostMapping("/applyJoinCompany")
    public Result applyJoinCompany(@RequestBody SysApplyJoinCompanyUserDTO sysApplyJoinCompanyUserDTO) {
       companyService.applyJoinCompany(sysApplyJoinCompanyUserDTO);
        return Result.success();
    }

    /**
     * 审核加入企业
     * @param sysAllowedJoinCompanyUserDTO
     * @return
     */
    @Override
    @PostMapping("/allowedJoinCompany")
    public Result allowedJoinCompany(SysAllowedJoinCompanyUserDTO sysAllowedJoinCompanyUserDTO) {

        companyService.allowedJoinCompany(sysAllowedJoinCompanyUserDTO);
        return Result.success();
    }

}
